<?php

// 从 URL 中取得主机名
function domainInfo ($url) {
	$html = file_get_contents("http://whois.ename.cn/whois.do?value={$url}");
	if(!preg_match_all("/dashed #C2DBF0' >(.*)<\/td>/i", $html, $matches)) return false;
	$domainInfo = array();
	foreach($matches[1] as &$match){
		$match = strip_tags($match);
		$match = str_replace("&nbsp;", "", $match);

		if (strpos($match, '注册者') !== false) {
			preg_match_all("/^注册者(.*)/i", $match, $register);
			$domainInfo['register'] = $register[1][0];
		}

		if (strpos($match, '域名联系人') !== false) {
			preg_match_all("/^域名联系人(.*)/i", $match, $owner);
			$domainInfo['owner'] = $owner[1][0];
		}

		if (strpos($match, '管理联系人电子邮件') !== false) {
			preg_match_all("/^管理联系人电子邮件(.*)/i", $match, $email);
			$domainInfo['email'] = $email[1][0];
		}

		if (strpos($match, '所属注册商') !== false) {
			preg_match_all("/^所属注册商(.*)/i", $match, $registrar);
			$domainInfo['registrar'] = $registrar[1][0];
		}

		if (strpos($match, '注册日期') !== false) {
			preg_match_all("/^注册日期(.*)/i", $match, $birthday);
			$domainInfo['birthday'] = $birthday[1][0];
		}

		if (strpos($match, '过期日期') !== false) {
			preg_match_all("/^过期日期(.*)/i", $match, $dieday);
			$domainInfo['dieday'] = $dieday[1][0];
		}
	}
	return $domainInfo;
}
/*
$url = "http://whois.ename.cn/whois.do?value=liuphp.com";
$domain = new DomainInfoFetch($url);
echo "<pre>";
var_dump($domain->);
echo "</pre>";
class DomainInfoFetch
{
	protected $_domain;
	protected $_html;
	protected $_matchCondition;

	private $_domainInfo;

	public function __construct($domain, $matchCondition = "/dashed #C2DBF0' >(.*)<\/td>/i")
	{
		$this->_domain = $domain;
		$this->_matchCondition = $matchCondition;
		$this->_html = $this->fetch();
		return $this->_domainInfo;
	}

	protected function fetch()
	{
		return file_get_contents($this->_domain);
	}

	protected function produce()
	{
		if (preg_match_all($this->_matchCondition, $this->_html, $matches)) {
			$domainInfo = array();
			foreach($matches[1] as &$match){
				$match = strip_tags($match);
				$match = str_replace("&nbsp;", "", $match);

				if (strpos($match, '注册者') !== false) {
					preg_match_all("/^注册者(.*)/i", $match, $register);
					$domainInfo['register'] = $register[1][0];
				}

				if (strpos($match, '域名联系人') !== false) {
					preg_match_all("/^域名联系人(.*)/i", $match, $owner);
					$domainInfo['owner'] = $owner[1][0];
				}

				if (strpos($match, '管理联系人电子邮件') !== false) {
					preg_match_all("/^管理联系人电子邮件(.*)/i", $match, $email);
					$domainInfo['email'] = $email[1][0];
				}

				if (strpos($match, '所属注册商') !== false) {
					preg_match_all("/^所属注册商(.*)/i", $match, $registrar);
					$domainInfo['registrar'] = $registrar[1][0];
				}

				if (strpos($match, '注册日期') !== false) {
					preg_match_all("/^注册日期(.*)/i", $match, $birthday);
					$domainInfo['birthday'] = $birthday[1][0];
				}

				if (strpos($match, '过期日期') !== false) {
					preg_match_all("/^过期日期(.*)/i", $match, $dieday);
					$domainInfo['dieday'] = $dieday[1][0];
				}
			}
			$this->_domainInfo = $domainInfo;
		} else {
			$this->_domailInfo = false;
		}
	}
}
*/
?> 